package app.v1.yd.mapper;

import app.v1.yd.domain.pojo.YdInventoryStatement;
import com.gitee.feizns.quickstart.mybatis.plus.QuickstartBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author feizns
 * @since 2023/09/11
 */
@Mapper
public interface YdInventoryStatementMapper extends QuickstartBaseMapper<YdInventoryStatement> {

    /**
     * 查询对应流程实例的数据编号
     * @param instanceId form inst编号
     * @return boolean
     */
    default YdInventoryStatement selectByInstanceId(@Param("instanceId") String instanceId) {
        return new YdInventoryStatement().setInstanceId(instanceId).selectOne();
    }

    /**
     * 根据仓库名称
     * @param warehouseName {@link String}
     */
    @Select("SELECT * FROM yd_inventory_statement y WHERE y.warehouse_name = #{warehouseName}")
    List<YdInventoryStatement> selectByWarehouseName(@Param("warehouseName") String warehouseName);

    /**
     * @param modifiedFormTime {@link LocalDateTime}
     */
    @Select("SELECT * FROM yd_inventory_statement y INNER JOIN yd_warehouse w ON y.warehouse_name = w.name AND w.enabled = 1  WHERE y.warehouse_name != '虚拟总仓' AND y.last_modified_time >= #{modifiedFormTime} OR y.create_time >= #{modifiedFormTime}")
    List<YdInventoryStatement> selectByCreateTimeAndLastModifiedTimeAfter(@Param("modifiedFormTime") LocalDateTime modifiedFormTime);

}
